local sk__youxu = fk.CreateSkill {

  name = "sk__youxu",

  tags = {  },

}



sk__youxu:addEffect(fk.EventPhaseStart, {
  name = "sk__youxu",
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(sk__youxu.name) and target.phase == Player.Play and not target.dead and
      target:isWounded() and #target:getCardIds("he") >= target:getLostHp()
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, sk__youxu.name, nil, "#sk__youxu-invoke::"..target.id..":"..target:getLostHp())
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    local n = target:getLostHp()
    local cards = room:askForCardsChosen(player, target, n, n, "he", sk__youxu.name, "#sk__youxu-card::"..target.id..":"..target:getLostHp())
    local choices = {"peach", "amazing_grace"}
    for i = 2, 1, -1 do
      local card = Fk:cloneCard(choices[i])
      card:addSubcards(cards)
      card.skillName = sk__youxu.name
      if not target:canUse(card) then
        table.remove(choices, i)
      end
    end
    if #choices == 0 then return end
    local choice = room:askForChoice(player, choices, sk__youxu.name, "#sk__youxu-choice::"..target.id)
    if choice == "peach" then
      room:useVirtualCard(choice, cards, target, target, sk__youxu.name, true)
    else
      room:useVirtualCard(choice, cards, target, table.filter(room:getAllPlayers(), function(p)
        local card = Fk:cloneCard("amazing_grace")
        card:addSubcards(cards)
        card.skillName = sk__youxu.name
        return not target:isProhibited(p, card)
      end), sk__youxu.name, true)
    end
  end,
})

return sk__youxu